import logging
from google.appengine.ext import db

class I18nText(db.Model):
	language = db.StringProperty(required=True, choices=set(["it", "en"]))
	
	text = db.TextProperty(required=True)
	
	

class I18nString(db.Model):
	language = db.StringProperty(required=True, choices=set(["it", "en"]))
	
	text = db.StringProperty(required=True)
	
	

class Ingredient(db.Model):
	names = db.ListProperty(db.Key)
	
	def addName(self, name):
		self.names.append(name)
		logging.debug("Added name, number of translations: " + str(len(self.names)) )
	
	def getName(self, locale):
		
		logging.debug("Number of translations: " + str(len(self.names)) )
		res = None
		for key in self.names:
			name = db.Model.get(key)
			if name.language == locale:
				res = name
				break
		
		if res != None:
			return res.text
		else:
			return u""

	